package com.example.demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.domain.Order;
import com.example.demo.domain.OrderRooms;
import com.example.demo.mapper.OrderMapper;
import com.example.demo.service.OrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: LiCheng
 * @CreateTime: 2024-11-07
 * @Description:
 * @Version: 1.0
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List<OrderRooms> listRooms(String roomNumber, List<Integer> flags) {

//        String flagString = flags.stream()
//                .map(Object::toString)
//                .collect(Collectors.joining(",", "IN (", ")"));
        List<OrderRooms>  orderRoomsList= orderMapper.listRooms( roomNumber,flags);
        return orderRoomsList;
    }

    @Override
    public PageInfo getListRoomsByPage(String roomNumber, List<Integer> flags, Integer pageNum, Integer pageSize) {

        // 查询mapper，顺便返回对应的数据
        PageHelper.startPage(pageNum,pageSize);
        List<OrderRooms> orderRoomsList = orderMapper.listRooms( roomNumber,flags);
        PageInfo pageInfo=new PageInfo(orderRoomsList);
        return pageInfo;
    }
}

